<template>
  <div>
    <!-- 管理员管理 -->

    <!-- 面包屑导航 -->
    <Crumbs></Crumbs>

    <!-- 组件切换 -->
    <div class="store_list">
      <div class="switchBtn">
        <button @click="storeListBtn1">管理员列表</button>
        <button @click="storeListBtn2" class="storeListBtn">添加管理员</button>
      </div>
    </div>
    <div class="admin-box">
      <el-form status-icon ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="管理员姓名">
          <el-input type="text" v-model="username" placeholder="请输入管理员姓名"></el-input>
        </el-form-item>
        <el-form-item label="账号">
          <el-input type="text" v-model="login" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="pwd" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item label="所属门店">
          <el-input type="text" v-model="shoplocation" placeholder="选择门店" style="width: 70%"></el-input>
          <el-button @click="dialogVisible = true">选择门店</el-button>
        </el-form-item>
        <el-form-item label="角色名称">
          <el-select v-model="role" placeholder="管理员">
            <el-option label="管理员" value="管理员"></el-option>
            <el-option label="发货" value="发货"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="form-btn" @click="preserve">保存</el-button>
        </el-form-item>
      </el-form>

      <!-- 选择门店 -->

      <el-dialog title="选择门店" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
        <SelectStore @choosep="choosep" @choicep="choicep"></SelectStore>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import SelectStore from './SelectStore.vue'
import Crumbs from '../Crumbs.vue'
import { getXaddAdminAdmin, getXAdminAdmin } from '../../../api'
export default {
  data() {
    return {
      username: '',
      login: '',
      pwd: '',
      shoplocation: '',
      role: '',
      state: '',
      //选择门店
      dialogVisible: false,
    }
  },
  methods: {
    storeListBtn1() {
      this.$router.push('/adminAdmin')
    },
    storeListBtn2() {
      this.$router.push('/addAdmin')
    },
    handleClose(done) {
      done()
    },
    preserve() {
      const obj = {
        username: this.username,
        login: this.login,
        pwd: this.pwd,
        shoplocation: this.shoplocation,
        role: this.role,
        state: this.state,
      }
      // console.log(obj.username);
      if (this.username == '' || this.login == '' || this.pwd == '' || this.shoplocation == '' || this.role == '') {
        this.$alert('信息不可为空', '提示', {
          confirmButtonText: '确定',
          callback: (action) => {
            this.$message({
              type: 'info',
              message: `action: ${action}`,
            })
          },
        })
      } else {
        getXaddAdminAdmin(obj).then((res) => {
          console.log(res)
        })
        this.$router.push('/adminAdmin')
        getXAdminAdmin().then((res) => {
          console.log(res.data)
          // this.tableData=res.data
        })
      }
    },
    choosep(res) {
      console.log(res)
      this.dialogVisible = res.flage
      this.store = res.title
    },
    choicep(res) {
      console.log(res)
      this.dialogVisible = res.flage
      this.store = res.title
    },
  },
  components: { SelectStore, Crumbs },
}
</script>
<style lang="scss" scoped>
.store_list {
  width: 1200px;
  margin: 0 auto;
  .switchBtn button {
    width: 100px;
    height: 30px;
    border: none;
    margin: 10px 30px 30px 0px;
    border-radius: 10px;
  }
  .storeListBtn {
    background: rgb(220, 183, 63);
    color: white;
  }
}
.demo-ruleForm {
  width: 500px;
}
.form-btn {
  margin: 0 auto;
}
</style>
